function initplus(callfun) {
    document.addEventListener('deviceready', function () {
        callfun(navigator)
    }, false);
}

 function GetAllRequest() {
	 var theRequest = new Object();
     var url = location.href;//直接获取href中的参数，不从search中获取
     
     if (url.indexOf("?") != -1) {
         var str = url.split('?')[1];
         str = str.split('#')[0];
         if (url.split('?').length > 2) {
             var str2 = url.split('?')[2];
             str = str + '&' + str2;
         }
         strs = str.split("&");
         for (var i = 0; i < strs.length; i++) {
			 var eqIndex = strs[i].indexOf("=");
             theRequest[strs[i].split("=")[0]] = unescape(strs[i].substr(eqIndex + 1));
         }
     }
     return theRequest;

}
function addplus() {
    var oHead = document.getElementsByTagName('HEAD').item(0);
    var oScript = document.createElement("script");
    oScript.type = "text/javascript";
	
	var maurl = "https://dev.yonyouccs.com";

    if (yonyou.browser.versions.mobile) {
		var theRequest = GetAllRequest();
        if (theRequest.fromType && theRequest.fromType == 'upEsnApp') {
            oScript.src = maurl + "/maservlet/html/yyplus/bridge.js";
            oHead.appendChild(oScript);
        } else {
            if (yonyou.browser.versions.ios) {
                oScript.src = maurl + "/maservlet/html/yyplus/ios/cordova.js";
                oHead.appendChild(oScript);
            } else if (yonyou.browser.versions.android) {
                oScript.src = maurl + "/maservlet/html/yyplus/android/cordova.js";
                oHead.appendChild(oScript);
            }
        }
    }
}

var yonyou = yonyou || {};
yonyou.browser = {
    versions: function () {
        var u = navigator.userAgent, app = navigator.appVersion;
        return {//移动终端浏览器版本信息
            trident: u.indexOf('Trident') > -1, //IE内核
            presto: u.indexOf('Presto') > -1, //opera内核
            webKit: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核
            gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, //火狐内核
            mobile: !!u.match(/AppleWebKit.*Mobile/) || !!u.match(/Windows Phone/) || !!u.match(/Android/) || !!u.match(/MQQBrowser/), //是否为移动终端
            ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
            android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android终端或者uc浏览器
            iPhone: u.indexOf('iPhone') > -1 || u.indexOf('Mac') > -1, //是否为iPhone或者QQHD浏览器
            iPad: u.indexOf('iPad') > -1, //是否iPad
            microMessenger: u.indexOf('MicroMessenger') > -1,	//是否为微信内置浏览器
            webApp: u.indexOf('Safari') == -1 //是否web应该程序，没有头部与底部
        };
    }(),
    language: (navigator.browserLanguage || navigator.language).toLowerCase()
}

addplus();

/*对接友空间原生轻应用交互方法*/
window.Bridge_YYPlugin = {
    call: function (plugin, fun, params, callback) {
        switch (fun) {
            case 'closewindow':
                if (typeof yyesn != 'undefined') {
                    //友空间进入
                    yyesn.client.closePage();
                } else {//移动门户进入
                    YYPlugin.call("CommonPlugin", "closewindow");
                }
                break;
            case 2:
                alert('222')
                break;
            default:
                alert('轻应用与原生交互产检调用错误！')
        }
    },
    camera: {
        getPicture: function (succFun, errFun, params) {
            if (typeof yyesn != 'undefined') {
                //友空间进入
                yyesn.client.selectAttachment(
                    succFun,
                    {'type': '4'});
            } else {//移动门户进入
                navigator.camera.getPicture(succFun, errFun, params);

            }
        },
    }
}


